// 链表反转

function fn(list) {
    if (!list) return null
    let head = list.next
    list.next = null
    while(head) {
        let temp = head.next
        head.next = list
        list = head
        head = temp
    }
    return list
}

// 头插法
function fun(list) {
    const head = { next: null }
    while(list) {
        let next = list.next
        list.next = head.next
        head.next = list
        list = next
    }
    return head.next
}

const list = {
    value: 0,
    next: {
        value: 1,
        next: {
            value: 2,
            next: null
        }
    }
}

console.log(fun(list))
console.log(fun(null))